package com.mmd.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

@WebFilter("/*")
public class CharsetEncodingFilter implements Filter {

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		// 过滤器业务逻辑处理
		//过滤器琏正向穿过时执行的代码块 
		//设置request编码
		request.setCharacterEncoding("utf-8");
		//设置request编码
		response.setCharacterEncoding("utf-8");
		chain.doFilter(request, response);
		//过滤琏反向穿过时执行的代码块
		
		System.out.println("执行了编码过滤器");
		//执行了设置编码过滤器
	}
	
	public void init(FilterConfig fConfig) throws ServletException{
		
	}

}
